home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77654_user_delete.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  12.7 KB  |  379 lines

  1. <%@ Language=VBScript   %>
  2. <%    Option Explicit     %>
  3. <%
  4.     '------------------------------------------------------------------------- 
  5.     ' user_delete.asp : Deletes the specified user
  6.     '
  7.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  8.     '
  9.     ' Date            Description
  10.     ' 15-jan-01        Creation date
  11.     '-------------------------------------------------------------------------
  12. %>
  13.     <!-- #include virtual="/admin/inc_framework.asp" -->
  14. <%
  15.     '-------------------------------------------------------------------------
  16.     ' Global Variables
  17.     '-------------------------------------------------------------------------
  18.     Dim rc                        'framework variables
  19.     Dim page                    'framework variables
  20.     Dim G_strUserName            'To save logged-in client user
  21.     
  22.     '-------------------------------------------------------------------------
  23.     ' Global Form Variables
  24.     '-------------------------------------------------------------------------
  25.     'Dim F_strUsername        'To save the user name got from the prevoius selected form
  26.     
  27.     '-------------------------------------------------------------------------
  28.     'Start of localization content
  29.     '-------------------------------------------------------------------------
  30.     Dim  L_PAGETITLE
  31.     'Dim  L_DELETETHEUSERMESSAGE
  32.     Dim  L_NOTE
  33.     Dim  L_NOTEBODY    
  34.     Dim  L_COULDNOTDELETEUSER_ERRORMESSAGE
  35.     Dim  L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  36.     Dim  L_USERNOTFOUND_ERRORMESSAGE
  37.     Dim  L_CANNOTDELETETHEUSERMESSAGE
  38.     Dim  L_UNABLETOGETSERVERVARIABLES    
  39.     Dim  L_COMPUTERNAME_ERRORMESSAGE
  40.     
  41.     Const N_COULDNOTDELETEBUILTINACCOUNTS_ERRNO     =&H8007055B
  42.     
  43.     L_PAGETITLE                                     = objLocMgr.GetString("usermsg.dll","&H4030003B", varReplacementStrings)
  44.     'L_DELETETHEUSERMESSAGE                         = objLocMgr.GetString("usermsg.dll","&H4030003C", varReplacementStrings)
  45.     L_NOTE                                         = objLocMgr.GetString("usermsg.dll","&H4030003D", varReplacementStrings)
  46.     L_NOTEBODY                                     = objLocMgr.GetString("usermsg.dll","&H4030003E", varReplacementStrings)
  47.     L_COULDNOTDELETEUSER_ERRORMESSAGE             = objLocMgr.GetString("usermsg.dll","&HC030003F", varReplacementStrings)
  48.     L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE = objLocMgr.GetString("usermsg.dll","&HC0300040", varReplacementStrings)
  49.     L_USERNOTFOUND_ERRORMESSAGE                     = objLocMgr.GetString("usermsg.dll","&HC0300041", varReplacementStrings)
  50.     L_CANNOTDELETETHEUSERMESSAGE                 = objLocMgr.GetString("usermsg.dll","&HC0300042", varReplacementStrings)
  51.     L_UNABLETOGETSERVERVARIABLES                 = objLocMgr.GetString("usermsg.dll","&H40300043", varReplacementStrings)
  52.     L_COMPUTERNAME_ERRORMESSAGE                     = objLocMgr.GetString("usermsg.dll","&HC0300044", varReplacementStrings)
  53.     '-----------------------------------------------------------------------------------
  54.     'END of localization content
  55.     '-----------------------------------------------------------------------------------
  56.     
  57.     ' Create a Property Page
  58.     rc = SA_CreatePage( L_PAGETITLE, "", PT_PROPERTY, page )
  59.     
  60.     ' Serve the page
  61.     rc = SA_ShowPage( page )
  62.     
  63.     '-------------------------------------------------------------------------
  64.     'Function:                OnInitPage()
  65.     'Description:            Called to signal first time processing for this page.
  66.     '                        Use this method to do first time initialization tasks
  67.     'Input Variables:        PageIn,EventArg
  68.     'Output Variables:        PageIn,EventArg
  69.     'Returns:                True/False
  70.     'Global Variables:        IN:G_strUserName
  71.     '-------------------------------------------------------------------------    
  72.     Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  73.         SA_TraceOut "TEMPLATE_PROPERTY", "OnInitPage"
  74.  
  75.         'Fucntion call to Get the logged in username
  76.         G_strUserName=GetUsername()
  77.         OnInitPage = TRUE
  78.         
  79.     End Function
  80.     
  81.     '-------------------------------------------------------------------------
  82.     'Function:                OnServePropertyPage()
  83.     'Description:            Called when the page needs to be served.Use this 
  84.     '                        method to serve content
  85.     'Input Variables:        PageIn,EventArg
  86.     'Output Variables:        PageIn,EventArg
  87.     'Returns:                True/False
  88.     'Global Variables:        L_(*)
  89.     '                        G_strUserName
  90.     '                        F_strUsername
  91.     '-------------------------------------------------------------------------    
  92.     Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  93.         
  94.         SA_TraceOut "TEMPLATE_PROPERTY", "OnServePropertyPage"
  95.         
  96.         ' Emit Functions required by Web Framework
  97.         Call ServeCommonJavaScript()
  98.         
  99.         Response.Write "<TABLE VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2 class='TasksBody'>"
  100.         
  101.         Dim itemCount
  102.         Dim itemKey
  103.         Dim bHave
  104.         Dim x
  105.         Dim sessionItem
  106.         Dim arrStrings(1)
  107.         Dim strParam
  108.         Dim strDeleteMsg
  109.         
  110.         bHave = false
  111.         itemCount = OTS_GetTableSelectionCount("")
  112.         For x = 1 to itemCount
  113.             If ( OTS_GetTableSelection("", x, itemKey) ) Then
  114.  
  115.                    Response.Write "<TR>"
  116.                 If VerifyUserAccount(itemKey) Then
  117.                     bHave = true     
  118.                     arrStrings(0) = itemKey   
  119.                     strParam = arrStrings
  120.                     strDeleteMsg = SA_GetLocString("usermsg.dll","&H4030003C", strParam)
  121.                     Response.Write "<TD>" & strDeleteMsg & "</TD>"
  122.                 Else 
  123.                     Response.Write    "<TD>" & L_CANNOTDELETETHEUSERMESSAGE & "</TD>"
  124.                 End If 
  125.                 Response.Write "</TR>"
  126.             End If
  127.             sessionItem = "Item" + CStr(x)
  128.             Session(sessionItem) = itemKey        
  129.         Next
  130.         
  131.         If bHave=true Then
  132.         %>
  133.             <TR>
  134.                 <TD colspan=2>
  135.                       
  136.                 </TD>
  137.             </TD>
  138.             <TR>
  139.                 <TD>
  140.                     <B><%=L_NOTE%></B>
  141.                 </TD>
  142.             </TR>
  143.             <TR>
  144.                 <TD width="590" height="20">
  145.                     <%=L_NOTEBODY%>
  146.                 </TD>
  147.             </TR>
  148.         <%End If%>
  149.         </TABLE>
  150.         <input type=hidden name="hdnLoggedInUserName"  value="<%=Server.HTMLEncode(G_strUserName)%>">
  151.         <%
  152.         OnServePropertyPage = TRUE
  153.     End Function
  154.  
  155.     '-------------------------------------------------------------------------
  156.     'Function:                OnPostBackPage()
  157.     'Description:            Called to signal that the page has been posted-back.
  158.     'Input Variables:        PageIn,EventArg
  159.     'Output Variables:        PageIn,EventArg
  160.     'Returns:                True/False
  161.     'Global Variables:        None
  162.     '-------------------------------------------------------------------------
  163.     Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  164.             OnPostBackPage = TRUE
  165.     End Function
  166.  
  167.     '-------------------------------------------------------------------------
  168.     'Function:                OnSubmitPage()
  169.     'Description:            Called when the page has been submitted for processing.
  170.     '                        Use this method to process the submit request.
  171.     'Input Variables:        PageIn,EventArg
  172.     'Output Variables:        PageIn,EventArg
  173.     'Returns:                True/False
  174.     'Global Variables:        None
  175.     '-------------------------------------------------------------------------
  176.     Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  177.         
  178.         SA_TraceOut "TEMPLATE_PROPERTY", "OnSubmitPage"
  179.         OnSubmitPage= DeleteUser()
  180.              
  181.     End Function
  182.     
  183.     '-------------------------------------------------------------------------
  184.     'Function:                OnClosePagee()
  185.     'Description:            Called when the page has been submitted for processing.
  186.     '                        Use this method to process the submit request.
  187.     'Input Variables:        PageIn,EventArg
  188.     'Output Variables:        PageIn,EventArg
  189.     'Returns:                True/False
  190.     'Global Variables:        None
  191.     '-------------------------------------------------------------------------
  192.     Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  193.         SA_TraceOut "TEMPLATE_PROPERTY", "OnClosePage"
  194.         OnClosePage = TRUE
  195.     End Function
  196.  
  197.     '-------------------------------------------------------------------------
  198.     'Function name:        DeleteUser()
  199.     'Description:        Serves in Updating users list
  200.     'Input Variables:    None
  201.     'Output Variables:    True or false
  202.     'Returns:            ( True / Flase )
  203.     '    True: If suceeds in updating the list
  204.     '    False:If fails in updating the list
  205.     'Global Variables:    In:L_USERNOTFOUND_ERRORMESSAGE
  206.     '                    In:L_COULDNOTDELETEUSER_ERRORMESSAGE
  207.     '                    In:L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  208.     '
  209.     'This function updates Serves in Updating users lists by deleting selected user
  210.     '
  211.     'If an error occurs, in getting the users list calls ServeFailurePage with
  212.     'the error string L_USERNOTFOUND_ERRORMESSAGE
  213.     '
  214.     'If an error occurs, in deleting the built-in account calls SetErrMsg with
  215.     'the error string L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  216.     '
  217.     'If an error occurs, in deleting the user, calls SetErrMsg with
  218.     'the error string L_COULDNOTDELETEUSER_ERRORMESSAGE
  219.     '-------------------------------------------------------------------------
  220.     Function DeleteUser
  221.         Err.Clear
  222.         On Error Resume Next    
  223.  
  224.         Dim nretval
  225.         Dim strComputerName
  226.         Dim objUser
  227.         Dim objComputer
  228.         
  229.         DeleteUser = FALSE
  230.         
  231.         'Gets the ComputerName from the system
  232.         strComputerName = GetComputerName()
  233.  
  234.         'Gets the UserNameObject from the system
  235.         Set objComputer = GetObject("WinNT://" & strComputerName & ",computer")
  236.         If Err.number  <> 0 Then
  237.             ServeFailurePage L_COMPUTERNAME_ERRORMESSAGE,1
  238.             Exit Function
  239.         End If
  240.         
  241.         Dim x
  242.         Dim itemCount
  243.         Dim itemKey
  244.         Dim sessionItem
  245.         
  246.         itemCount = OTS_GetTableSelectionCount("")
  247.         
  248.         For x = 1 to itemCount
  249.             If ( OTS_GetTableSelection("", x, itemKey) ) Then
  250.             
  251.                 'Checking for the existence of the user
  252.                 Set objUser = objComputer.GetObject("User",itemKey)
  253.                 
  254.                 If Err.number <> 0 Then
  255.                     SetErrMsg L_USERNOTFOUND_ERRORMESSAGE
  256.                     Exit Function
  257.                 End If
  258.                 
  259.                 'deletes the Username from the System
  260.                 nretval = objComputer.Delete("User" , itemKey)
  261.         
  262.                 If Err.Number <> 0 Then
  263.                     If Err.Number = N_COULDNOTDELETEBUILTINACCOUNTS_ERRNO  Then
  264.                         SetErrMsg L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE & "(" & itemKey & ")"
  265.                     Else
  266.                         SetErrMsg L_COULDNOTDELETEUSER_ERRORMESSAGE & "(" & itemKey & ")"
  267.                     End IF
  268.                     Exit Function
  269.                 End If
  270.                 
  271.             End If
  272.             sessionItem = "Item" + CStr(x)
  273.             Session(sessionItem) = itemKey        
  274.         Next
  275.         
  276.         Set objUser= Nothing
  277.         Set objComputer =Nothing
  278.         
  279.         DeleteUser = TRUE
  280.         
  281.     End function
  282.  
  283.     '-------------------------------------------------------------------------
  284.     'Function name:        GetUsername()
  285.     'Description:        Serves in getting the logged-in client user
  286.     'Input Variables:    None
  287.     'Output Variables:    None
  288.     'Returns:            string -Either Logged in username  or null
  289.     'Global Variables:    In:L_UNABLETOGETSERVERVARIABLES
  290.     'If an error occurs, in getting ServerVariables calls SetErrMsg with
  291.     'the error string L_UNABLETOGETSERVERVARIABLES
  292.     '-------------------------------------------------------------------------
  293.     Function GetUsername()
  294.         Err.Clear
  295.         On Error Resume Next
  296.  
  297.         Dim strDomainUserName
  298.         Dim strUserName
  299.  
  300.         strDomainUserName = Request.ServerVariables("REMOTE_USER")
  301.         If Err.Number <> 0 Then
  302.             SetErrMsg L_UNABLETOGETSERVERVARIABLES
  303.             GetUsername = ""
  304.         End if
  305.  
  306.         If InStr(strDomainUserName, "\") Then
  307.             strUserName = Split(strDomainUserName,"\")
  308.             GetUsername    =    strUserName(1)
  309.         Else
  310.             GetUsername = strDomainUserName
  311.         End If
  312.         
  313.     End Function
  314.  
  315.     '-------------------------------------------------------------------------
  316.     'Function name:        VerifyUserAccount()
  317.     'Description:        Serves in verifying the logged-in client user
  318.     'Input Variables:    None
  319.     'Output Variables:    True or false
  320.     'Returns:            ( True / Flase )
  321.     '    True: If selected user is logged-in client user
  322.     '    False:If selected user is not logged-in client user
  323.     'Global Variables:    In:F_strUsername - selected user for deletion
  324.     '                    In:G_strUserName - logged-in client user
  325.     'This function Serves in verifying the logged-in client user
  326.     'by comparing it with the selected user for deletion
  327.     '
  328.     '-------------------------------------------------------------------------
  329.     Function VerifyUserAccount(strUserName)
  330.     
  331.     'verifying the logged-in client user
  332.       If strUserName=G_strUserName then
  333.           VerifyUserAccount=false
  334.       else
  335.            VerifyUserAccount=true
  336.       end if
  337.       
  338.     End function
  339.  
  340.     '-------------------------------------------------------------------------
  341.     'Function:                ServeCommonJavaScript
  342.     'Description:            Serves in initialiging the values,setting the form
  343.     '                        data and validating the form values
  344.     'Input Variables:        None
  345.     'Output Variables:        None
  346.     'Returns:                None
  347.     'Global Variables:        None
  348.     '-------------------------------------------------------------------------
  349.     Function ServeCommonJavaScript()
  350.     %>
  351.         <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  352.         </script>
  353.         <script language="JavaScript">
  354.         
  355.         // Init Function
  356.         function Init()
  357.         {
  358.             SetPageChanged(false);
  359.         }
  360.  
  361.         // ValidatePage Function
  362.         // Returns: True if the page is OK, false if error(s) exist. 
  363.         function ValidatePage()
  364.         {
  365.             return true;
  366.         }
  367.  
  368.  
  369.         // SetData Function
  370.         // This function must be included or a javascript runtime error will occur.
  371.         function SetData()
  372.         {
  373.         }
  374.         
  375.         </script>
  376.     <%
  377.     End Function
  378. %>
  379.